$(function(){
    if (getQueryString('key') != '') {
        var key = getQueryString('key');
        var username = getQueryString('username');
        addCookie('key', key);
        addCookie('username', username);
    } else {
        var key = getCookie('key');
    }
    var username = ''
	if(key){
        $("#loginOut").show();
        $.ajax({
            type:'post',
            url:ApiUrl+"/index.php?act=member_index",
            data:{key:key},
            dataType:'json',
            success:function(result){
                console.log(result);
                username = result['datas']['member_info']['user_name'];
                var html = '<span class="right"><a href="./recharge_mobile.html">充值</a></span><p><a href="member_setting.html"><img class="touxiang"src="'+result['datas']['member_info']['avatar']+'"></a></p><p class="username">'+username+'</p>';
                //渲染页面
                $(".center").html(html);

                var html = '<p>余额 <span>'+result['datas']['member_info']['available_predeposit']+'</span></p><p><a href="pointslog_list.html">积分 <span>'+result['datas']['member_info']['member_points']+'</span></a></p>';
                //渲染页面
                $(".footer").html(html);
                if (result['datas']['member_info']['store_id']) {
                    addCookie('store_id', result['datas']['member_info']['store_id']);
                } else {
                    delCookie('store_id');
                }
                if (result['datas']['member_info']['agent_id'] > 0) {
                    $("#agent").show();
                }

                if(result['datas']['member_info']['store_class']==0){
                      $("#mystore").remove();
                }else{
                      $("#yx").after('<li id="mystore"><a href="check_vr_code.html" id="sq" style="display:block;"><img src="../../images/m_05.png" alt=""/><span style="padding-left: 10px;">我的商圈</span></a></li>');
                }

                $('.touxiang').attr('src',"http://"+window.location.host+"/data/upload/shop/common/default_user_portrait.gif");
                return false;
            }
        });

	} else {
	    var html = '<span class="right"><a href="./recharge_mobile.html">充值</a></span><p><img class="touxiang"src="http://'+window.location.host+'/data/upload/shop/common/default_user_portrait.gif"></p><div class="gologin"><a href="'+WapSiteUrl+'/tmpl/member/login.html">立即登录</a></div>';
	    //
	    $(".center").html(html);
        $("#loginOut").hide();
        return false;
	}

    $('#loginOut').on('click',function(){
        $.ajax({
            type:'post',
            url:ApiUrl+"/index.php?act=logout",
            data:{client:'wap',username:username,key:key},
            dataType:'json',
            success:function(result){
                 delCookie('key');
                 window.location.href = 'login.html';
            }
        });
    })
	  //滚动header固定到顶部
	  //$.scrollTransparent();
});